package com.breezelin.freshmarket.entities.rsp;

/**
 * Created by Breeze Lin
 * 2016/5/16 09:22
 * breezesummerlin@163.com
 */

import com.breezelin.freshmarket.entities.JsonStruct;
import com.breezelin.freshmarket.entities.data.Category;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取所有类别的回应
 */
public class CategoriesRsp implements JsonStruct {

	/**
	 * 类别
	 */
	private List<Category> categories;

	public CategoriesRsp() {
	}

	public CategoriesRsp(JSONObject jsonObject) {
		fromJson(jsonObject);
	}

	public List<Category> getCategories() {
		return categories;
	}

	@Override
	public void fromJson(JSONObject jsonObject) {
		categories = new ArrayList<>();
		JSONArray categoriesJson = jsonObject.optJSONArray("Categorys");
		if (categoriesJson != null) {
			for (int i = 0; i < categoriesJson.length(); i++) {
				categories.add(new Category(categoriesJson.optJSONObject(i)));
			}
		}
	}

	@Override
	public JSONObject toJson() {
		return new JSONObject();
	}
}
